<template>
    <div>
        <el-button type="primary" plain @click="add">添加</el-button>
        <el-table
            :data="rolelist"
            row-key="id"
            border
            style="width: 100%"
            :tree-props="{ children: 'children' }"
        >
            <el-table-column prop="id" label="角色编号" width="100">
            </el-table-column>
            <el-table-column prop="rolename" label="角色名称"> </el-table-column>
            <el-table-column prop="status" label="状态">
                <template slot-scope="scope">
                    <el-tag type="success" plain size="middle">{{
                        scope.row.status == 1 ? "启用" : "禁用"
                    }}</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="操作" ref="role">
                <template slot-scope="scope">
                    <el-button type="primary" icon="el-icon-edit"  circle @click="edit(scope.row)"></el-button>
                    <el-button type="danger" icon="el-icon-delete" circle @click="del(scope.row.id)"></el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
//引入vuex
import Vuex from "vuex";
export default {
    data() {
        return {};
    },
    methods: {
        //引入 角色列表 接口
        ...Vuex.mapActions({
            getlist: "role/rolelist_a",
            roledel: "role/roledelete_a",
            roleinfo: "role/roleinfo_a",
        }),
        //点击添加
        add() {
            this.$emit("changeBtn",true)
            
        },
        //点击编辑
        edit(row) {
            this.$emit("changeBtn", false); //点击编辑 不是添加按钮
            this.roleinfo(row.id);
        },
        //点击删除
        del(id) {
            //点击弹出
            this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    this.roledel(id);
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消删除",
                    });
                });
        },
    },
    mounted() {
        //调用
        this.getlist();
    },
    computed: {
        //引入 角色列表数据
        ...Vuex.mapGetters({
            rolelist: "role/getrolelist",
            // roleform :"role/roleinfo",
        }),
    },
};
</script>

<style scoped></style>
